<?php include("head.php"); 

include_once("../Adminincludes/config.php");

$selectQuery="SELECT * FROM ". STATICPAGE;

$selectExe=mysql_query($selectQuery);

if(mysql_num_rows($selectExe)>0)

	{   

		$content=mysql_fetch_array($selectExe);
	
		$fld=$_REQUEST['val'];
	
		$showContent=$content[$fld];

	}

if(isset($_REQUEST['Edit']))

  	 {
  $cont=addslashes($_REQUEST['content']);

		if($_GET['action']='edit')
		
		{
            // echo '<script>alert("'.$daydiff[0].'");</script>';
		$updatesql="update ".STATICPAGE." set contents ='".$cont."',pageName='".$_REQUEST['pageName']."' WHERE pageName='".$_REQUEST['val']."' and langId='".$_REQUEST['SelectLang']."'";
			echo $updatesql.'<br><br><br>'; 
			$sqlpage=mysql_query($updatesql);
			
			echo "<script>window.location='staticpage.php?&m=1'</script>";
		}
	
	}

if(isset($_REQUEST['insert']))

  	 {
  $cont=addslashes($_REQUEST['content']);
		{
	
			$sql1="INSERT INTO ".STATICPAGE." SET `langId`=".$_REQUEST['SelectLang'].", contents='".$cont."',pageName='".$_REQUEST['pageName']."'";
			echo $sql1;
			$sqlpage=mysql_query($sql1);
			
			echo "<script>window.location='staticpage.php?&m=1'</script>";
	
		}
	

	}

   



?>

<script>

 function changeVal(val)

 {
   if(val !="")
    window.location="staticpage.php?action=edit&val="+val;
   else
     window.location="staticpage.php";
   	return false;
 }
<?php if($_REQUEST['val']!='' && $_REQUEST['val']=='insert')
	{
 		$temp=1;

	}
 	elseif($_REQUEST['val']!='' && $_REQUEST['val'] !='insert')
	{
		$temp=2;

	}
	else
	{
		$temp=0;

	}
?>
</script>
<fieldset>
<legend class="LEGEND">Edit&nbsp;<?php echo ucfirst($_REQUEST['val']);?> Page  Details</legend>

<form name="static_page" action="" method="POST" >

<table width="100%" border="0"  cellpadding="5" cellspacing="0">

	<tr>
		<td width="25%">&nbsp;</td>
		<td width="75%"><?php if($_REQUEST['m']==1)
		{?>
		<font color="blue">Page Updated Succesfully</font>
		<?php }?>		</td>
	</tr>
	<?php if($temp=='0' || $temp=='1'){ ?>

       <tr id="add_page"> 

           	<td colspan="2">Add New Page&nbsp;<a href="staticpage.php?val=insert">Click Here </a></td>
	</tr>
	<?php }?>

	<?php if($temp=='0' || $temp=='2'){ ?>
		<tr>
		  <td>Select Page Name : </td>
		  <td><select name="page"  size="1"  onchange="changeVal(this.value)">
            <option value="" selected="selected">Select Page For Edit</option>
            <?php
			$sql="SELECT * FROM ".STATICPAGE." where langId='1'";
			$result = mysql_query($sql);
	
			if (mysql_num_rows($result) > 0)
			{
	
			while ($row = mysql_fetch_assoc($result)) 
				{
		
					$namefinal='';
			
					$namerow=explode("_",$row['pageName']);
			
					$num=count($namerow);
		
				for($i=0;$i<$num;$i++)
					{
						$namefinal.=$namerow[$i].' ';
			
					}
				?>
            <option value="<?php echo $row['pageName']; ?>" <?php if(isset($_GET['val']) && ($_GET['val']==$row['pageName'])) echo 'selected'; ?>><?php echo $namefinal;?></option>
            <?php
	
				}

			}

			?>
          </select></td>
       </tr>
<?php  }?>


	<tr>
		<td>&nbsp;</td>
		<td>&nbsp;</td>		
	</tr>

<?php if(($_GET['val']!='') || ($_GET['action']!=''))

	{

	$fetchval=mysql_query("SELECT * FROM ".STATICPAGE." WHERE pageName ='".$_GET['val']."' ")or die(mysql_error());
//echo "SELECT * FROM ".STATICPAGE."WHERE pageName ='".$_GET['val']."'";
	$fetch1=mysql_fetch_array($fetchval);
	$value=ucfirst(stripslashes($fetch1['contents']));

?>
	<tr>
		<td>Select Language </td>
		<td>
					<?php

						$selectlanguage="SELECT * FROM ".LANGUAGE;
						$Exequery=mysql_query($selectlanguage) or die("Selection Error Language :<br>".$selectlanguage.'<br>'.mysql_error());
						if(mysql_num_rows($Exequery) > 0)
						{
					?>
					<select name="SelectLang" id="SelectLang">
						<option value="" <?php if($fetch1['langId'] == '' || $fetch1['langId'] == 0 ) echo 'selected';?>>--Select one--</option>
					<?php
							while($resultExequery = mysql_fetch_assoc($Exequery))
							{
								if($resultExequery['langId'] == $fetch1['langId'])
									$selected="selected";
								else
									$selected="";
					?>
						<option value="<?php echo $resultExequery['langId']?>" <?php echo $selected; ?>><?php echo $resultExequery['langName']?></option>
					<?php
							}
					?>
					</select>
					<?php
						}
					?>
					
				
				</td>		
	</tr>



	<tr>
		<td>Page Content : </td>	
		<td>	
		<?php 		
		include_once ('../vendor/FCKeditor/fckeditor.php');
		$oFCKeditor = new FCKeditor('content');
		$oFCKeditor->BasePath = '../vendor/FCKeditor/';
		$oFCKeditor->Value = $value;	
		$oFCKeditor->Width  = '95%';
		$oFCKeditor->Height = '400';	
		$oFCKeditor->Config['SkinPath'] = 'skins/office2003/' ;
		$oFCKeditor->Create();
		
		?>		</td>
	</tr>
	<tr>
		<td >Page Name : </td>
		<td><input type="text" name="pageName" value="<?php echo $fetch1['pageName'];?>"></td>
	</tr>
	<tr>
		<td>&nbsp;</td>
		<td><?php if($_GET['val']=='insert'){?><input type="submit" name="insert" value="Insert"><?php } else  {?> <input type="submit" name="Edit" value="Update"><?php } ?>&nbsp;&nbsp;<input type="button" value="Cancel" name="close_frm" id="close_frm" onclick="window.location='staticpage.php';" /></td>
	</tr>



<?php } ?>
</table>

</form>

</fieldset>

<?php 
echo $_GET['val'];
include("foot.php");
 ?>